package com.example.campuslink.commen.db.message

import android.os.Message
import androidx.room.Entity
import androidx.room.Ignore
import androidx.room.PrimaryKey
import androidx.room.TypeConverters
import com.example.campuslink.commen.db.MessageBeanConverter
import com.example.campuslink.commen.db.invitation.InvitationDao
import com.example.campuslink.commen.db.invitation.InvitationTable
import com.example.campuslink.model.MessageBeanData

@Entity(tableName = "message_table")
//@TypeConverters(MessageBeanConverter::class)
data class MessageTable(
    @PrimaryKey(autoGenerate = true)
    var id: Int = 0,
    var handNumber: String = "",
    var sendNumber: String = "",
//    var messageBeanData: MutableList<MessageBeanData>? = null
    var messageType:String = "",
    var messageContent:String = "",
    var messageImage:String = "",
    var messageTime:Long = 0,
    var invitationId:Int = 0,
    var commendId:Int = 0
) {
    @Ignore
    constructor() : this(id = 0, handNumber = "", sendNumber = "",  messageType = "", messageContent = "", messageImage = "", messageTime = 0
    ,invitationId = 0, commendId = 0)

    companion object {
        suspend fun insertWithId(
            dao: MessageDao,
            message: MessageTable
        ) {
            val maxId = dao.getMaxId() ?: 0
            dao.insertMessage(message.copy(id = maxId + 1))
        }
    }
}
